
$(function () {
    let parems = {
        page: '',
        perpage: 10
    }
    // 将评论数据渲染到页面中 
    function getComment() {
        $.get('/admin/comment/search', parems, function (res) {
            console.log(res)
            const html = template('art_comment', { data: res.data.data })
            // console.log(html)
            $('tbody').html(html)
            renderPage(res.data.totalCount)
        })
    }
    // 分页设置
    function renderPage(count) {
        layui.laypage.render({
            elem: 'pager',//注意，这里的ID，不用加 # 号
            count,
            limit: parems.perpage,
            curr: parems.page,
            jump: function (obj, first) {
                if (!first) {
                    parems.page = obj.curr;
                    getComment()
                }
            }
        });
    }
    // 评论审核通过
    $('tbody').on('click', '.btnAccept', function () {
        const { id } = $(this).parents('tr').data('obj')
        $.post('/admin/comment/pass', { id }, function (res) {
            console.log(res)
            getComment()
        })
    })

    // 评论不通过
    $('tbody').on('click', '.btnReject', function () {
        const { id } = $(this).parents('tr').data('obj')
        $.post('/admin/comment/reject', { id }, function (res) {
            console.log(res)
            getComment()
        })
    })


    // 删除评论
    $('tbody').on('click', '.btnDelete', function () {
        const { id } = $(this).parents('tr').data('obj')
        $.post('/admin/comment/delete', { id }, function (res) {
            console.log(res)
            getComment()
        })
    })
    getComment()
})